PREFIX  = /usr/local
ARCH    = h8300-elf
BINDIR  = $(PREFIX)/bin
ADDNAME = $(ARCH)-

AR      = $(BINDIR)/$(ADDNAME)ar
AS      = $(BINDIR)/$(ADDNAME)as
CC      = $(BINDIR)/$(ADDNAME)gcc
LD      = $(BINDIR)/$(ADDNAME)ld
NM      = $(BINDIR)/$(ADDNAME)nm
OBJCOPY = $(BINDIR)/$(ADDNAME)objcopy
OBJDUMP = $(BINDIR)/$(ADDNAME)objdump
RANLIB  = $(BINDIR)/$(ADDNAME)ranlib
STRIP   = $(BINDIR)/$(ADDNAME)strip

OBJS    = startup.o main.o
OBJS   += lib.o serial.o interrupt.o
OBJS   += kozos.o syscall.o memory.o
OBJS   += romtest.o xmodem.o

TARGET  = romtest

CFLAGS  = -Wall -mh -nostdinc -nostdlib -fno-builtin
#CFLAGS += -mint32
CFLAGS += -I.
#CFLAGS += -g
CFLAGS += -Os
CFLAGS += -fomit-frame-pointer
CFLAGS += -DKOZOS

LFLAGS  = -static -T ld.scr -L.

.SUFFIXES: .c .o
.SUFFIXES: .s .o
.SUFFIXES: .S .o

all :       $(TARGET)

$(TARGET) : $(OBJS)
			$(CC) $(OBJS) -o $(TARGET) $(CFLAGS) $(LFLAGS)
			cp $(TARGET) $(TARGET).elf
			readelf -a $(TARGET).elf > readelf.out
			$(STRIP) $(TARGET)

.c.o :      $<
			$(CC) -c $(CFLAGS) $<

.s.o :      $<
			$(CC) -c $(CFLAGS) $<

.S.o :      $<
			$(CC) -c $(CFLAGS) $<

clean :
			rm -f $(OBJS) $(TARGET) $(TARGET).elf
